/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.delivery.service;

import com.mycompany.delivery.entities.Account;
import java.util.HashSet;
import java.util.Set;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;

/**
 *
 * @author mhunek
 */
public class AccountAdapter extends User {
    
    public AccountAdapter(Account account) {
        super(account.getLogin(), account.getPassword(), account.isEnabled(), 
                true, true, true, toAuthorities(account.getRoles()));
        
    }
    
    private static Set<GrantedAuthority> toAuthorities(Set<String> roles) {
        Set<GrantedAuthority> auths = new HashSet<>();
        for (String role : roles) {
            auths.add(new SimpleGrantedAuthority(role));
        }
        return auths;
    }
}
